package org.stvd.entities.oauth;

import java.util.Date;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.Table;
import javax.persistence.Transient;

import org.springframework.format.annotation.DateTimeFormat;
import org.stvd.core.annotation.serializer.DateTimeSerializer;
import org.stvd.entities.base.BaseEntity;

import com.fasterxml.jackson.databind.annotation.JsonSerialize;

/**
 * 认证授权Token-实体类
 * @author houzx
 */
@Entity
@Table(name = "oauth_access_token")
public class OauthAccessToken extends BaseEntity{

    private static final long serialVersionUID = 8134616948619145268L;

    /**
     * token ID
     */
    @Id
    @Column(name = "token_id", nullable = false)
    private  String tokenId = "";
    
    /**
     * token值
     */
    @Column(name = "token", nullable = false)
    private byte[] token = null;
    
    /**
     * 授权ID
     */
    @Column(name = "authentication_id")
    private String authenticationId = "";
    
    /**
     * 用户ID
     */
    @Column(name = "user_name")
    private String userName = "";
    
    /**
     * 客户端ID
     */
    @Column(name = "client_id")
    private String clientId = "";
    
    /**
     * 授权信息
     */
    @Column(name = "authentication")
    private byte[] authentication = null;
    
    /**
     * 刷新Token
     */
    @Column(name = "refresh_token")
    private String refreshToken = "";
    
    /**
     * 创建时间
     */
    @Column(name = "create_time", nullable = false)
    @DateTimeFormat(pattern="yyyy-MM-dd HH:mm:ss")
    @JsonSerialize(using = DateTimeSerializer.class)
    private Date createTime = null;

    /**
     * 授权类型{password; client_credentials}
     */
    @Transient
    private String grantType = "";
    
    public String getTokenId() {
        return tokenId;
    }

    public void setTokenId(String tokenId) {
        this.tokenId = tokenId;
    }

    public byte[] getToken() {
        return token;
    }

    public void setToken(byte[] token) {
        this.token = token;
    }

    public String getAuthenticationId() {
        return authenticationId;
    }

    public void setAuthenticationId(String authenticationId) {
        this.authenticationId = authenticationId;
    }

    public String getUserName() {
        return userName;
    }

    public void setUserName(String userName) {
        this.userName = userName;
    }

    public String getClientId() {
        return clientId;
    }

    public void setClientId(String clientId) {
        this.clientId = clientId;
    }

    public byte[] getAuthentication() {
        return authentication;
    }

    public void setAuthentication(byte[] authentication) {
        this.authentication = authentication;
    }

    public String getRefreshToken() {
        return refreshToken;
    }

    public void setRefreshToken(String refreshToken) {
        this.refreshToken = refreshToken;
    }

    public Date getCreateTime() {
        return createTime;
    }

    public void setCreateTime(Date createTime) {
        this.createTime = createTime;
    }

    public String getGrantType() {
        return grantType;
    }

    public void setGrantType(String grantType) {
        this.grantType = grantType;
    }
}
